package LeedCode.StackDemo;

import java.util.EmptyStackException;
import java.util.Stack;

public class Main {

    public static void  showpush(Stack<Integer> stack,int a){
        stack.push(a);
        System.out.println("push: "+a);
        System.out.println("stack: "+stack);
    }
    public static   void showpop(Stack<Integer> stack){
        System.out.println("pop: "+stack.pop());
        System.out.println("stack"+stack);
    }
    public  static void main(String[] args){
        Stack<Integer> integerStack=new Stack<>();
        System.out.println("stack"+integerStack);
        showpush(integerStack,1);
        showpush(integerStack,2);
        showpush(integerStack,3);
        showpush(integerStack,4);
        System.out.println("stack"+integerStack);
        showpop(integerStack);
        showpop(integerStack);
        showpop(integerStack);
        showpop(integerStack);
        try {
            showpop(integerStack);//尝试需要执行可能会报错的代码块
        }catch (EmptyStackException e){//空栈类型然后进行错误处理
            System.out.println("Empty Stack");
        }

    }


}
